package org.example;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.concurrent.TimeUnit;


@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Thread)
@Fork(1)
@Warmup(iterations = 3)
@Measurement(iterations = 10)
public class JMHMain {

    private double[] res;

    @Benchmark
    public void testYyFloat64AddSub() {
        res = yyFloat64AddSub(0, 314159265);
    }

    @TearDown(Level.Iteration)
    public void showRes() {
        System.out.printf("结果:( %f, %f)\t耗时：", res[0], res[1]);
    }

    public double[] yyFloat64AddSub(double n1, double n2) {
        for (int i = 1; i <= 100000000; i++) {
            n1 += 3.14;
            n2 -= 3.14;
        }
        return new double[]{n1, n2};
    }

    public static void main(String[] args) throws Exception {
        Options opt = new OptionsBuilder()
                .include(JMHMain.class.getSimpleName())
                .build();
        new Runner(opt).run();
    }
}